package com.demo.mqtt.picker.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.demo.mqtt.common.fromCommon.dto.SplitPageDTO;
import com.demo.mqtt.common.fromCommon.response.ResponseResult;
import com.demo.mqtt.common.fromResource.LoginUser;
import com.demo.mqtt.common.fromResource.entity.SysUser;
import com.demo.mqtt.picker.entity.dto.PickerInfoDTO;
import com.demo.mqtt.picker.entity.vo.PickerInfoVO;
import com.demo.mqtt.picker.service.IPickerInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: mqtt
 * @description: 数采器
 * @author: liuYunKai
 * @create: 2021-03-30 15:29
 */
@Api(value = "数采器信息接口", tags = {"数采器信息接口"})
@RestController
@RequestMapping("/picker")
public class PickerInfoController {
    @Autowired
    private IPickerInfoService pickerInfoService;

    @ApiOperation("查询数采器列表")
    @GetMapping("/page")
    public ResponseResult<IPage<PickerInfoVO>> page(SplitPageDTO splitPageDTO, PickerInfoDTO pickerInfoDTO, @LoginUser SysUser sysUser) {
        return ResponseResult.ok(pickerInfoService.getPickinfoPage(splitPageDTO, pickerInfoDTO,sysUser));
    }

    @ApiOperation("添加数采器")
    @PostMapping("/save_picker")
    public ResponseResult<String> pickerSave(@RequestBody PickerInfoDTO pickerInfoDTO) {
        pickerInfoService.pickerSave(pickerInfoDTO);
        return ResponseResult.ok();
    }

    /**
     * 更新数采器
     *
     * @return
     */
    @ApiOperation("更新数采器")
    @PutMapping("update/{id}")
    public ResponseResult<String> dasUpdateById(@PathVariable String id,
                                                @RequestBody PickerInfoDTO pickerInfoDTO) {
        pickerInfoService.updateByDTO(id, pickerInfoDTO);
        return ResponseResult.ok();
    }


    @ApiOperation("删除数采器")
    @DeleteMapping("/{id}")
    public ResponseResult<String> del(@PathVariable String id) {
        boolean b = pickerInfoService.removeById(id);
        return ResponseResult.ok();
    }
}
